<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui">
	
      <p:dialog widgetVar="pnlEditOrder" header="Alterar pedido" modal="true" resizable="false" draggable="false" closable="false" width="280">
        <p:outputPanel id="pnlEditOrder">  
        <p:messages />
        <h:panelGrid columns="3" >
          <h:outputText value="Data recebimento:" rendered="#{orderAction.actionArriveItem}" />
          <p:spacer width="8" rendered="#{orderAction.actionArriveItem}" />
          <p:calendar id="arriveDate" value="#{orderAction.order.arriveDate}" pattern="dd/MM/yyyy" rendered="#{orderAction.actionArriveItem}" 
                      required="true" mode="popup" showOn="button" popupIconOnly="true" readOnlyInputText="true" inputStyle="width:120px;"
                      requiredMessage="Data recebimento obrigatoria!" 
                      validatorMessage="Data recebimento inválida!"  
                      converterMessage="Data recebimento inválida!" />  
          <h:outputText value="Data venda" rendered="#{orderAction.actionSellItem}" />
          <p:spacer width="8" rendered="#{orderAction.actionSellItem}" />
          <p:calendar id="sellDate" value="#{orderAction.order.sellDate}" pattern="dd/MM/yyyy" rendered="#{orderAction.actionSellItem}" 
                      required="true" mode="popup" showOn="button" popupIconOnly="true" readOnlyInputText="true" inputStyle="width:120px;"
                      requiredMessage="Data venda obrigatoria!" 
                      validatorMessage="Data venda inválida!"  
                      converterMessage="Data venda inválida!" />  
          <h:outputText value="Valor venda:" rendered="#{orderAction.actionSellItem}" />
          <p:spacer width="8" rendered="#{orderAction.actionSellItem}" />
          <p:inputText id="sellValue" value="#{orderAction.order.sellValue}"  rendered="#{orderAction.actionSellItem}"
                       required="true" requiredMessage="Valor venda obrigatorio"
                       converterMessage="Valor venda inválido"
                       validatorMessage="Valor venda inválido"
                       onkeyup="formataValor(this,'.',',')" >
                       <f:validateDoubleRange minimum="0.01" />
                       <f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="pt_BR" pattern="#,##0.00" />
          </p:inputText>
          <h:outputText value="Situação venda:" rendered="#{orderAction.actionSellItem}" />
          <p:spacer width="8" rendered="#{orderAction.actionSellItem}" />
          <h:panelGroup rendered="#{orderAction.actionSellItem}">
            <h:selectBooleanCheckbox id="sellStatus" value="#{orderAction.order.sellStatus.receivePayment}" rendered="#{orderAction.actionSellItem}"></h:selectBooleanCheckbox><h:outputText value="Pagamento recebido." rendered="#{orderAction.actionSellItem}" />
          </h:panelGroup>
          <h:outputText value="Data pagamento" rendered="#{orderAction.actionPayItem}" />
          <p:spacer width="8" rendered="#{orderAction.actionPayItem}" />
          <p:calendar id="paymentDate" value="#{orderAction.order.paymentDate}" pattern="dd/MM/yyyy" rendered="#{orderAction.actionPayItem}" 
                      required="true" mode="popup" showOn="button" popupIconOnly="true" readOnlyInputText="true" inputStyle="width:120px;"
                      validatorMessage="Data pagamento inválida!"  
                      converterMessage="Data pagamento inválida!" />  
          <h:outputText value="Cotação moeda:" rendered="#{orderAction.actionPayItem and orderAction.order.dollar}" />
          <p:spacer width="8" rendered="#{orderAction.actionPayItem and orderAction.order.dollar}" />
          <p:inputText id="currencyValue" value="#{orderAction.order.currencyValue}" rendered="#{orderAction.actionPayItem and orderAction.order.dollar}"
                       required="true" requiredMessage="Valor cotação obrigatorio" 
                       converterMessage="Valor cotação inválido"
                       validatorMessage="Valor cotação inválido"
                       onkeyup="formataValor(this,'.',',')" >  
                       <p:ajax update="totalDollarValue, totalRealValue" />                     
                       <f:validateDoubleRange minimum="0.01" />
                       <f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="pt_BR" pattern="#,##0.00" />
          </p:inputText>
          <h:outputText value="Valor:" rendered="#{orderAction.actionPayItem}" />
          <p:spacer width="8" rendered="#{orderAction.actionPayItem}" />
          <p:inputText id="buyValue" value="#{orderAction.order.buyValue}" rendered="#{orderAction.actionPayItem}"
                       required="true" requiredMessage="Valor compra obrigatorio" 
                       converterMessage="Valor compra inválido"
                       validatorMessage="Valor compra inválido"
                       onkeyup="formataValor(this,'.',',')" >  
                       <p:ajax update="totalDollarValue, totalRealValue" />                     
                       <f:validateDoubleRange minimum="0.01" />
                       <f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="pt_BR" pattern="#,##0.00" />
          </p:inputText>
          <h:outputText value="Frete:" rendered="#{orderAction.actionPayItem}" />
          <p:spacer width="8" rendered="#{orderAction.actionPayItem}" />
          <p:inputText id="shippingValue" value="#{orderAction.order.shippingValue}"  rendered="#{orderAction.actionPayItem}"
                       converterMessage="Valor frete inválido" 
                       validatorMessage="Valor frete inválido"
                       onkeyup="formataValor(this,'.',',')" >
                       <p:ajax update="totalDollarValue, totalRealValue" />
                       <f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="pt_BR" pattern="#,##0.00" />
          </p:inputText>                     
          <h:outputText value="Taxas:" rendered="#{orderAction.actionPayItem}" />
          <p:spacer width="8" rendered="#{orderAction.actionPayItem}" />
          <p:inputText id="taxValue" value="#{orderAction.order.taxValue}"  rendered="#{orderAction.actionPayItem}"  
                       converterMessage="Valor taxa inválido" 
                       validatorMessage="Valor taxa inválido"
                       onkeyup="formataValor(this,'.',',')" >
                       <p:ajax update="totalDollarValue, totalRealValue" />
                       <f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="pt_BR" pattern="#,##0.00" />
          </p:inputText>                     
          <h:outputText value="Valor total U$:" rendered="#{orderAction.actionPayItem and orderAction.order.dollar}" />
          <p:spacer width="8" rendered="#{orderAction.actionPayItem and orderAction.order.dollar}" />
          <p:inputText id="totalDollarValue" value="#{orderAction.order.totalDollarBuyValue}" readonly="true" rendered="#{orderAction.actionPayItem and orderAction.order.dollar}" >
                       <f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="pt_BR" pattern="#,##0.00" />
          </p:inputText>                     
          <h:outputText value="Valor total R$:" rendered="#{orderAction.actionPayItem}" />
          <p:spacer width="8" rendered="#{orderAction.actionPayItem}" />
          <p:inputText id="totalRealValue" value="#{orderAction.order.totalBuyValue}" readonly="true" rendered="#{orderAction.actionPayItem}" >
                       <f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="pt_BR" pattern="#,##0.00" />
          </p:inputText>                     
        </h:panelGrid>
        <h:panelGrid columns="1" rendered="#{orderAction.actionReceivePaymentItem or orderAction.actionDelete}" >
          <h:outputText value="Confirma receber pagamento desse produto?" rendered="#{orderAction.actionReceivePaymentItem}" ></h:outputText>
          <h:panelGroup rendered="#{orderAction.actionReceivePaymentItem}">
            <h:selectBooleanCheckbox id="confirmActionReceive" value="#{orderAction.confirmAction}"></h:selectBooleanCheckbox><h:outputText value="Confirmo pagamento do pedido #{orderAction.order.id}." />
          </h:panelGroup>
          <h:outputText value="Confirma excluir esse pedido?" rendered="#{orderAction.actionDelete}" ></h:outputText>
          <h:panelGroup rendered="#{orderAction.actionDelete}">
            <h:selectBooleanCheckbox id="confirmActionDelete" value="#{orderAction.confirmAction}"></h:selectBooleanCheckbox><h:outputText value="Confirmo exclusão do pedido #{orderAction.order.id}." />
          </h:panelGroup>
        </h:panelGrid>
        <p:spacer height="10" />
        <h:panelGrid columns="1" >
          <h:panelGroup >
            <p:commandButton action="#{orderAction.deleteOrder}" value="confirmar" update="pnlEditOrder,tblOrders" oncomplete="closeDialog(xhr, status, args)" rendered="#{orderAction.actionDelete}" />
            <p:commandButton action="#{orderAction.updateStatusOrder}" value="confirmar" update="pnlEditOrder,tblOrders" oncomplete="closeDialog(xhr, status, args)" rendered="#{!orderAction.actionDelete}" />
            <p:spacer width="10" />
            <p:commandButton action="#{orderAction.clearAction}" oncomplete="pnlEditOrder.hide();" value="cancelar" immediate="true" />
          </h:panelGroup>
        </h:panelGrid>
        </p:outputPanel>
      </p:dialog>    
      
      <script type="text/javascript">  
        function closeDialog(xhr, status, args) {  
          if(!(args.hasBusinessException || args.validationFailed)) {  
        	  pnlEditOrder.hide();  
          }  
       }  
      </script>        

</ui:composition>

